/*
 *  Copyright (C) 2011 Hatsites <Hatsites_AT_gmail.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package org.myorg.shr.dtb.structure.db.table;

import java.util.Vector;
import org.myorg.shr.dtb.structure.dtb.tbl.fld.FldTypAbs;

/**
 *
 * @author Hatsites
 *
 * email: Hatsites_AT_gmail.com
 * ... please remove "_AT_" from the above string to get the right email address
 *
 */

abstract public class TblAbs {

    protected TblAbs(String strName){
        this._strName_             = strName;
        this._strsFieldName        = new Vector<String>();
        this._strsFieldType        = new Vector<FldTypAbs>();
        this._intsFieldSize        = new Vector<Integer>();
        this._strsFieldReference   = new Vector<String>();
        this._tablesTableReference = new Vector<TblAbs>();
        this._strsRecording        = new Vector<String>();
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException();
    }

    public void setValue(String strKey, String strValue){
        int i = _strsFieldName.indexOf(strKey);
        _strsRecording.setElementAt(strValue, i);
    }

    public String getValue(int index){
        return _strsRecording.get(index);
    }

    public String getValue(String strKey){
        int i = _strsFieldName.indexOf(strKey);
        return _strsRecording.get(i);
    }



    protected void add(
            String strFieldName,
            FldTypAbs strFieldType,
            Integer strFieldSize,
            String strRecording){
        this._strsFieldName.add(strFieldName);
        this._strsFieldType.add(strFieldType);
        this._intsFieldSize.add(strFieldSize);
        this._tablesTableReference.add(null);
        this._strsFieldReference.add(null);
        this._strsRecording.add(strRecording);
    }

    protected void add(
            String strFieldName,
            FldTypAbs strFieldType,
            String strRecording){
        this._strsFieldName.add(strFieldName);
        this._strsFieldType.add(strFieldType);
        this._intsFieldSize.add(null);
        this._tablesTableReference.add(null);
        this._strsFieldReference.add(null);
        this._strsRecording.add(strRecording);
    }

    protected void add(
            String strFieldName,
            FldTypAbs strFieldType,
            TblAbs refTable,
            String refField,
            String strRecording){
        this._strsFieldName.add(strFieldName);
        this._strsFieldType.add(strFieldType);
        this._intsFieldSize.add(null);
        this._tablesTableReference.add(refTable);
        this._strsFieldReference.add(refField);
        this._strsRecording.add(strRecording);
    }

    public String getName(){
        return this._strName_;
    }

    public String getFieldName(int i){
        return _strsFieldName.get(i);
    }

    public FldTypAbs getFieldType(int i){
        return _strsFieldType.get(i);
    }

    public Integer getFieldSize(int i){
        return _intsFieldSize.get(i);
    }

    public TblAbs getReferenceTable(int i){
        return _tablesTableReference.get(i);
    }

    public String getReferenceField(int i){
        return _strsFieldReference.get(i);
    }

    public int countFields(){
        return this._strsFieldName.size();

    }

    private String _strName_;
    private Vector<String> _strsFieldName;
    private Vector<FldTypAbs> _strsFieldType;
    private Vector<Integer> _intsFieldSize;
    private Vector<TblAbs> _tablesTableReference;
    private Vector<String> _strsFieldReference;
    private Vector<String> _strsRecording;
    
}
